//
//  ViewController.m
//  18-SQLite
//
//  Created by 王道林 on 16/8/8.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "ViewController.h"
#import "SQLiteDataBaseManager.h"
#import "Student.h"

@interface ViewController ()
@property (nonatomic, strong) SQLiteDataBaseManager *dateBaseManager;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _dateBaseManager = [SQLiteDataBaseManager shareManager];
    
    // SQLite3
    // 注意: 使用SQLite需要引入liasqlite3.o.tbd
    // libsqlite3.0.tbd 和 libsqlite3.tbd区别
    //  libsqlite3.0.tbd是libsqlite3.tbd的替身文件, 防止用户误删
    
    
}


- (IBAction)openSQLite:(id)sender {
    
    [_dateBaseManager openSQlite3];
}


- (IBAction)closeSQLite:(id)sender {
    [_dateBaseManager closeSQLite3];
    
}



- (IBAction)createTable:(id)sender {
    
    [_dateBaseManager crateTable];
}

- (IBAction)addData:(id)sender {
    Student *stu = [[Student alloc] init];
    stu.stu_id = 38;
    stu.stu_name = @"李其昌";
    
    [_dateBaseManager insertStu:stu];
    
}

- (IBAction)deleteData:(id)sender {
//    Student *stu = [[Student alloc] init];
//    stu.stu_id = 38;
//    stu.stu_name = @"李其昌";
//    [_dateBaseManager deleteStu:stu];
    
    [_dateBaseManager deleteAll];
}


- (IBAction)updataName:(id)sender {
 
    [_dateBaseManager updataOldName:@"李其昌" newName:@"xxx"];
}

- (IBAction)selectData:(id)sender {
    
   NSArray *arr = [_dateBaseManager selectAll];
    NSLog(@"%@",arr);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
